package com.cinema.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单实体类
 */
public class Order {
    private Integer id;
    private String orderNo;
    private Integer userId;
    private Integer showtimeId;
    private BigDecimal totalAmount;
    private Integer ticketCount;
    private String status;
    private String paymentMethod;
    private Date paymentTime;
    private Date expireTime;
    private Date createdAt;
    private Date updatedAt;
    
    // 关联对象
    private User user;
    private Showtime showtime;
    private List<OrderSeat> orderSeats;
    
    // 构造方法
    public Order() {}
    
    public Order(String orderNo, Integer userId, Integer showtimeId, BigDecimal totalAmount, Integer ticketCount) {
        this.orderNo = orderNo;
        this.userId = userId;
        this.showtimeId = showtimeId;
        this.totalAmount = totalAmount;
        this.ticketCount = ticketCount;
    }
    
    // Getter和Setter方法
    public Integer getId() {
        return id;
    }
    
    public void setId(Integer id) {
        this.id = id;
    }
    
    public String getOrderNo() {
        return orderNo;
    }
    
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    
    public Integer getUserId() {
        return userId;
    }
    
    public void setUserId(Integer userId) {
        this.userId = userId;
    }
    
    public Integer getShowtimeId() {
        return showtimeId;
    }
    
    public void setShowtimeId(Integer showtimeId) {
        this.showtimeId = showtimeId;
    }
    
    public BigDecimal getTotalAmount() {
        return totalAmount;
    }
    
    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public Integer getTicketCount() {
        return ticketCount;
    }
    
    public void setTicketCount(Integer ticketCount) {
        this.ticketCount = ticketCount;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public String getPaymentMethod() {
        return paymentMethod;
    }
    
    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }
    
    public Date getPaymentTime() {
        return paymentTime;
    }
    
    public void setPaymentTime(Date paymentTime) {
        this.paymentTime = paymentTime;
    }
    
    public Date getExpireTime() {
        return expireTime;
    }
    
    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }
    
    public Date getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }
    
    public Date getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    public User getUser() {
        return user;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
    public Showtime getShowtime() {
        return showtime;
    }
    
    public void setShowtime(Showtime showtime) {
        this.showtime = showtime;
    }
    
    public List<OrderSeat> getOrderSeats() {
        return orderSeats;
    }
    
    public void setOrderSeats(List<OrderSeat> orderSeats) {
        this.orderSeats = orderSeats;
    }
    
    /**
     * 判断订单是否已过期
     */
    public boolean isExpired() {
        return expireTime != null && new Date().after(expireTime);
    }
    
    /**
     * 判断是否可以退票
     */
    public boolean canRefund() {
        return "PAID".equals(status) && showtime != null && 
               showtime.getShowTime() != null && 
               new Date().before(showtime.getShowTime());
    }
    
    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", orderNo='" + orderNo + '\'' +
                ", userId=" + userId +
                ", showtimeId=" + showtimeId +
                ", totalAmount=" + totalAmount +
                ", ticketCount=" + ticketCount +
                ", status='" + status + '\'' +
                ", expireTime=" + expireTime +
                '}';
    }
}
